package com.study.base.netty.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @description: NioFileChannel04
 * @date: 2021/1/21 13:47
 * @author: hcm
 * @version: 1.0
 */
public class NioFileChannel04 {
    public static void main(String[] args) throws IOException {

        //创建相关的流
        FileInputStream fileInputStream = new FileInputStream("d:\\a.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("d:\\b.jpg");

        //获取各个流对应的Filechannel
        FileChannel source = fileInputStream.getChannel();
        FileChannel target = fileOutputStream.getChannel();

        //使用transferform完成拷贝
        target.transferFrom(source,0,source.size());
        //关闭流
        source.close();
        target.close();
        fileInputStream.close();
        fileOutputStream.close();

    }
}

